using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartLink.DTOS;
using SmartLink.EnumLibrary;
using SmartLink.Infrastructure;

namespace SmartLink.Application.Services
{
    /// <summary>
    /// 响应实体
    /// </summary>
    public class InfrastructureAppService
    {
        private InfrastructureAppService()
        {
        }

        public static Results<T> Response<T>(T data, string msg, int state)
        {
            return new Results<T> { State = state, Message = msg, Data = data };
        }

        public static Results<T> Response<T>(T data)
        {
            return Response(data, StateCodeEnum.成功.ToString(), StateCodeEnum.成功.GetHashCode());
        }

        public static Results<T> Response<T>(string msg, int state)
        {
            return Response(default(T), msg, state);
        }

        public static Results<T> Response<T>(string msg, StateCodeEnum state)
        {
            return Response(default(T), msg, (int)state);
        }

        public static Results Response(string msg, int state)
        {
            return new Results() { State = state, Message = msg };
        }

        public static Results Response(string msg, StateCodeEnum state)
        {
            return new Results() { State = (int)state, Message = msg };
        }

        public static Results Response()
        {
            return Response(StateCodeEnum.成功.ToString(), StateCodeEnum.成功);
        }

        public static Results Transmit(OperationResult opResult)
        {
            return new Results
            {
                State = (opResult.ResultType == OperationResultType.Success || opResult.ResultType == OperationResultType.NoChanged)
                    ? (int)StateCodeEnum.成功 : (int)StateCodeEnum.失败,
                Message = !string.IsNullOrEmpty(opResult.Message) ? opResult.Message : EnumHelper.GetDesription(opResult.ResultType)
            };
        }
        public static Results<T> Transmit<T>(OperationResult opResult)
        {
            return new Results<T>
            {
                State = (opResult.ResultType == OperationResultType.Success || opResult.ResultType == OperationResultType.NoChanged)
                    ? (int)StateCodeEnum.成功 : (int)StateCodeEnum.失败,
                Message = !string.IsNullOrEmpty(opResult.Message) ? opResult.Message : EnumHelper.GetDesription(opResult.ResultType)
            };
        }
    }
}
